<template>
	<div>
		<el-form :model="form" :rules="rules" ref="fromref" class="form-box">
			<h3 style="color: #606266;">管理员登录页面</h3>
			<el-form-item prop="account">
				<el-input v-model="form.account" suffix-icon="el-icon-user" placeholder="用户名"></el-input>
			</el-form-item>
			<el-form-item prop="password">
				<el-input type="password" v-model="form.password" suffix-icon="el-icon-lock" placeholder="密码"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="submitForm('fromref')">登录</el-button>
				<el-button @click="resetForm('fromref')">重置</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				form: {
					account: '',
					password: ''
				},
				rules: {
					account: [{
							required: true,
							message: '请输入账号',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 6,
							message: '长度在 3 到 6 个字符',
							trigger: 'blur'
						}
					],
					password: [{
							required: true,
							message: '请输入密码',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 6,
							message: '长度在 3 到 6 个字符',
							trigger: 'blur'
						}
					]
				}
			}
		},
		methods: {
			resetForm(formName) {
				this.$refs[formName].resetFields()
			},
			submitForm(formName) {
				this.$refs[formName].validate(async (valid) => {
					if (valid) {
						var param=new URLSearchParams()
						param.append("account",this.form.account)
						param.append("password",this.form.password)
						var res= await this.$http.post('/selectAdminByAccountAndPassword', param)
						console.log(res.data)
						if (res.data.code != 200) {
							this.$message.error(res.data.message)
						} else {
							this.$message.success('登录成功！')
							/* 动态菜单需要 */
							window.sessionStorage.setItem('Admin',JSON.stringify(res.data.data))
							/* 角色登录验证token */
						/* 	window.sessionStorage.setItem('token', res.data.data.token) */
							this.$router.push('/h_index')
						}
				
					} else {
						this.$message({
						         showClose: true,
						         message: 'error submit!',
						         type: 'error'
						});
						return false
					}
				})
			}
		}
	}
</script>
<style>
	.form-box {
		width: 350px;
		padding: 20px 50px;
		margin: 0px auto;
		margin-top: 200px;
		box-shadow: 0 8px 16px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
		border-radius: 10px;
		text-align: center;
	}
</style>
